package com.kejiguan.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.R;
import com.kejiguan.ui.model.ExhibitionNeItem;
import com.kejiguan.ui.util.CommonDate;

import java.util.List;

/**
 * Created by apple on 16/3/2.
 */
public class DisplayItemAdapter extends RecyclerView.Adapter<DisplayItemVH>{

    private Context mContext;
    private List<ExhibitionNeItem> presenterItems;
    private LayoutInflater mInflater;
    private View.OnClickListener onClickListener;

    private int color1,color2,color3;


    public DisplayItemAdapter(Context mContext,List<ExhibitionNeItem> presenterItems)
    {
        this.mContext=mContext;
        this.presenterItems=presenterItems;
        mInflater=LayoutInflater.from(mContext);
        color1=mContext.getResources().getColor(R.color.text_color1);
        color2=mContext.getResources().getColor(R.color.text_color2);
        color3=mContext.getResources().getColor(R.color.text_color3);
    }

    @Override
    public DisplayItemVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.fragment_display_item_layout,null);
        return new DisplayItemVH(itemView);
    }

    @Override
    public void onBindViewHolder(DisplayItemVH holder, int position) {

        ExhibitionNeItem presenterItem=presenterItems.get(position);
        holder.displayNameView.setText(presenterItem.getExhibitionName());
        if(CommonDate.STATE_RUNNING.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg2);
            holder.displayNameView.setTextColor(color2);
        }else if (CommonDate.STATE_EXCEPTION.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
            holder.displayNameView.setTextColor(color3);
        }else if (CommonDate.STATE_OPEN_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
            holder.displayNameView.setTextColor(color3);
        }else if (CommonDate.STATE_CLOSE_TIME_OUT.equals(presenterItem.getExhibitionState()))
        {
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg3);
            holder.displayNameView.setTextColor(color3);
        }else
        {
            holder.displayNameView.setBackgroundResource(R.drawable.kjg_item_display_bg1);
            holder.displayNameView.setTextColor(color1);
        }
        if (null!=onClickListener)
        {
            holder.displayNameView.setOnClickListener(onClickListener);
            holder.displayNameView.setTag(R.id.recyclerview_item_position,presenterItem);
        }

    }

    @Override
    public int getItemCount() {
        if (null==presenterItems)
        {
            return 0;
        }else
        {
            return presenterItems.size();
        }

    }

    public void setPresenterItems(List<ExhibitionNeItem> presenterItems) {
        this.presenterItems = presenterItems;
        notifyDataSetChanged();
    }

    public void setOnClickListener(View.OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}
